package com.codi.bus.core.dao.impl;

import com.codi.base.dao.v2.GeneratedBaseDaoImpl;
import com.codi.bus.core.dao.ProfitDao;
import com.codi.bus.core.domain.Profit;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zengxl
 * @Description:
 * @Date: 2018/5/4 10:15
 */
@Repository
public class ProfitDaoImpl extends GeneratedBaseDaoImpl<Profit> implements ProfitDao {
    @Override
    public List<Profit> selectAccumulateProfit(Profit profit) {
        return this.findList("selectAccumulateProfit", profit);
    }

    @Override
    public List<Profit> selectAccumulateProfitOneDay(String dateTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("dateTime",dateTime);
        return this.findList("selectAccumulateProfitOneDay",map);
    }

    @Override
    public List<Profit> selectProfit(Profit profit) {
        return this.findList("selectProfit", profit);
    }

    @Override
    public List<Profit> selectProfitByFundCode(Integer userId, String tradeAcco, String fundCode, Date dateTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("tradeAcco", tradeAcco);
        map.put("fundCode", fundCode);
        map.put("dateTime", dateTime);
        return this.findList("selectProfitByFundCode", map);
    }

    @Override
    public List<Profit> selectNewProfit(Integer userId, String clientId, String tradeAcco, String fundCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        map.put("tradeAcco", tradeAcco);
        map.put("fundCode", fundCode);
        return this.findList("selectNewProfit", map);
    }

    @Override
    public List<Profit> selectNewCreateProfit(Integer userId, String clientId, String tradeAcco, String fundCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        map.put("tradeAcco", tradeAcco);
        map.put("fundCode", fundCode);
        return this.findList("selectNewCreateProfit", map);
    }

    @Override
    public List<Profit> selectNewPortfolioProfit(Integer userId, String clientId, String DateTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        map.put("DateTime", DateTime);
        return this.findList("selectNewPortfolioProfit", map);
    }

    @Override
    public List<Profit> selectAllNewProfit(Integer userId, String clientId, String fundCode) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        map.put("fundCode", fundCode);
        return this.findList("selectAllNewProfit", map);
    }

    @Override
    public List<Profit> selectFundCode(Integer userId, String clientId) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("clientId", clientId);
        return this.findList("selectFundCode", map);
    }

    @Override
    public List<Profit> selectAccumulateByFundCode(Integer userId, String tradeAcco, String fundCode, Date dateTime) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("tradeAcco", tradeAcco);
        map.put("fundCode", fundCode);
        map.put("dateTime", dateTime);
        return this.findList("selectAccumulateByFundCode", map);
    }

    @Override
    public List<Profit> selectZc(String dateTime) {
        return this.findList("selectZc", dateTime);
    }

    @Override
    public List<Profit> selectProfitByUserAndTime(Integer userId, String beginDate, String endDate) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("beginDate", beginDate);
        map.put("endDate", endDate);
        return this.findList("selectProfitByUserAndTime", map);
    }

    /**
     * 根据用户id和组合交易账号查询收益信息
     *
     * @param userId
     * @param tradeAcco
     * @return
     */
    @Override
    public List<Profit> selectProfitByUserIdAndTradeAcco(Long userId, String tradeAcco) {
        Map<String, Object> map = new HashMap<>();
        map.put("userId", userId);
        map.put("tradeAcco", tradeAcco);
        return this.findList("selectProfitByUserIdAndTradeAcco", map);
    }


    @Override
    public int deleteByDateTime(String dateTime) {
        Profit profit = Profit.builder().dateTime(dateTime).build();
        return super.delete(generateStatement("deleteByDateTime"), profit);
    }

    @Override
    public int deleteByCreateTime(String createTime) {
        Profit profit = Profit.builder().createTime(createTime).build();
        return super.delete(generateStatement("deleteByCreateTime"), profit);
    }
}
